package SSF.OS.NetFlow.Filter;

import com.renesys.raceway.SSF.*;
import com.renesys.raceway.DML.*;

import java.util.*;

/**
 * Like Filter, but it's composed by one or more "AND phrase"(Factor).
 * @see Filter
 * @see Factor
 */
public class Term implements BasicFilter
{
    /** factors within this term*/
    private LinkedList factors;

    public Term(Filter parentFilter, Configuration cfg) 
	throws configException
    {
	factors = new LinkedList();

	//config the factors
	for (Enumeration factorConfigs = cfg.find("factor");
	     factorConfigs.hasMoreElements();) {
	    factors.addLast(new Factor(parentFilter,(Configuration)(factorConfigs.nextElement())));
	}
    }

    /** whether the given record satisfies this term*/
    @Override
	public boolean passFilter(FilterData record)
    {
	/*	for (int i=0; i<factors.length; i++) {
	    if (factors[i].passFilter(record)==false)
		return false;
	}
	*/
	Factor f;
	for (ListIterator iter = factors.listIterator();
	     iter.hasNext();) {
	    f = (Factor)iter.next();
	    if (f.passFilter(record)==false)
		return false;
	}
	return true;
    }

}
